package com.whut.cristiano.autographbook.Model;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.whut.cristiano.autographbook.MyApplication;
import com.whut.cristiano.autographbook.R;
import com.whut.cristiano.autographbook.VO.CircleItem;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ykbboom on 2017/3/16 15:53
 * email：ykbpro@whut.edu.cn
 */

public class CircleAdapter extends RecyclerView.Adapter<CircleAdapter.ViewHolder> {

    private List<CircleItem> list;
    private Context context = MyApplication.getContext();
    public CircleAdapter(List<CircleItem> list){
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.circle_item,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        CircleItem item = list.get(position);
        Glide.with(context).load(item.getPicUrl()).into(holder.cardItem);
        holder.time.setText(item.getTime());
        holder.name.setText(item.getName());
        Glide.with(context).load(item.getUserPhoto()).into(holder.img);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        CircleImageView img;
        TextView time;
        TextView name;
        ImageView cardItem;
        public ViewHolder(View view){
            super(view);
            img = (CircleImageView) view.findViewById(R.id.my_request_item_photo);
            time = (TextView) view.findViewById(R.id.my_request_item_time);
            name = (TextView) view.findViewById(R.id.my_request_item_name);
            cardItem = (ImageView) view.findViewById(R.id.my_request_item_img);
        }
    }
}
